/* eslint-disable */
import _m0 from "protobufjs/minimal";
import { FieldMask } from "../../google/protobuf/field_mask";
import { Timestamp } from "../../google/protobuf/timestamp";
import { RowStatus, Visibility } from "./common";

export const protobufPackage = "slash.api.v1";

export interface Memo {
  id: number;
  creatorId: number;
  createdTime: Date | undefined;
  updatedTime: Date | undefined;
  rowStatus: RowStatus;
  name: string;
  title: string;
  content: string;
  tags: string[];
  visibility: Visibility;
}

export interface ListMemosRequest {
}

export interface ListMemosResponse {
  memos: Memo[];
}

export interface GetMemoRequest {
  id: number;
}

export interface GetMemoResponse {
  memo: Memo | undefined;
}

export interface CreateMemoRequest {
  memo: Memo | undefined;
}

export interface CreateMemoResponse {
  memo: Memo | undefined;
}

export interface UpdateMemoRequest {
  memo: Memo | undefined;
  updateMask: string[] | undefined;
}

export interface UpdateMemoResponse {
  memo: Memo | undefined;
}

export interface DeleteMemoRequest {
  id: number;
}

export interface DeleteMemoResponse {
}

function createBaseMemo(): Memo {
  return {
    id: 0,
    creatorId: 0,
    createdTime: undefined,
    updatedTime: undefined,
    rowStatus: 0,
    name: "",
    title: "",
    content: "",
    tags: [],
    visibility: 0,
  };
}

export const Memo = {
  encode(message: Memo, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
    if (message.id !== 0) {
      writer.uint32(8).int32(message.id);
    }
    if (message.creatorId !== 0) {
      writer.uint32(16).int32(message.creatorId);
    }
    if (message.createdTime !== undefined) {
      Timestamp.encode(toTimestamp(message.createdTime), writer.uint32(26).fork()).ldelim();
    }
    if (message.updatedTime !== undefined) {
      Timestamp.encode(toTimestamp(message.updatedTime), writer.uint32(34).fork()).ldelim();
    }
    if (message.rowStatus !== 0) {
      writer.uint32(40).int32(message.rowStatus);
    }
    if (message.name !== "") {
      writer.uint32(50).string(message.name);
    }
    if (message.title !== "") {
      writer.uint32(58).string(message.title);
    }
    if (message.content !== "") {
      writer.uint32(66).string(message.content);
    }
    for (const v of message.tags) {
      writer.uint32(74).string(v!);
    }
    if (message.visibility !== 0) {
      writer.uint32(80).int32(message.visibility);
    }
    return writer;
  },

  decode(input: _m0.Reader | Uint8Array, length?: number): Memo {
    const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseMemo();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 8) {
            break;
          }

          message.id = reader.int32();
          continue;
        case 2:
          if (tag !== 16) {
            break;
          }

          message.creatorId = reader.int32();
          continue;
        case 3:
          if (tag !== 26) {
            break;
          }

          message.createdTime = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
          continue;
        case 4:
          if (tag !== 34) {
            break;
          }

          message.updatedTime = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
          continue;
        case 5:
          if (tag !== 40) {
            break;
          }

          message.rowStatus = reader.int32() as any;
          continue;
        case 6:
          if (tag !== 50) {
            break;
          }

          message.name = reader.string();
          continue;
        case 7:
          if (tag !== 58) {
            break;
          }

          message.title = reader.string();
          continue;
        case 8:
          if (tag !== 66) {
            break;
          }

          message.content = reader.string();
          continue;
        case 9:
          if (tag !== 74) {
            break;
          }

          message.tags.push(reader.string());
          continue;
        case 10:
          if (tag !== 80) {
            break;
          }

          message.visibility = reader.int32() as any;
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },

  create(base?: DeepPartial<Memo>): Memo {
    return Memo.fromPartial(base ?? {});
  },

  fromPartial(object: DeepPartial<Memo>): Memo {
    const message = createBaseMemo();
    message.id = object.id ?? 0;
    message.creatorId = object.creatorId ?? 0;
    message.createdTime = object.createdTime ?? undefined;
    message.updatedTime = object.updatedTime ?? undefined;
    message.rowStatus = object.rowStatus ?? 0;
    message.name = object.name ?? "";
    message.title = object.title ?? "";
    message.content = object.content ?? "";
    message.tags = object.tags?.map((e) => e) || [];
    message.visibility = object.visibility ?? 0;
    return message;
  },
};

function createBaseListMemosRequest(): ListMemosRequest {
  return {};
}

export const ListMemosRequest = {
  encode(_: ListMemosRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
    return writer;
  },

  decode(input: _m0.Reader | Uint8Array, length?: number): ListMemosRequest {
    const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseListMemosRequest();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },

  create(base?: DeepPartial<ListMemosRequest>): ListMemosRequest {
    return ListMemosRequest.fromPartial(base ?? {});
  },

  fromPartial(_: DeepPartial<ListMemosRequest>): ListMemosRequest {
    const message = createBaseListMemosRequest();
    return message;
  },
};

function createBaseListMemosResponse(): ListMemosResponse {
  return { memos: [] };
}

export const ListMemosResponse = {
  encode(message: ListMemosResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
    for (const v of message.memos) {
      Memo.encode(v!, writer.uint32(10).fork()).ldelim();
    }
    return writer;
  },

  decode(input: _m0.Reader | Uint8Array, length?: number): ListMemosResponse {
    const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseListMemosResponse();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 10) {
            break;
          }

          message.memos.push(Memo.decode(reader, reader.uint32()));
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },

  create(base?: DeepPartial<ListMemosResponse>): ListMemosResponse {
    return ListMemosResponse.fromPartial(base ?? {});
  },

  fromPartial(object: DeepPartial<ListMemosResponse>): ListMemosResponse {
    const message = createBaseListMemosResponse();
    message.memos = object.memos?.map((e) => Memo.fromPartial(e)) || [];
    return message;
  },
};

function createBaseGetMemoRequest(): GetMemoRequest {
  return { id: 0 };
}

export const GetMemoRequest = {
  encode(message: GetMemoRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
    if (message.id !== 0) {
      writer.uint32(8).int32(message.id);
    }
    return writer;
  },

  decode(input: _m0.Reader | Uint8Array, length?: number): GetMemoRequest {
    const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseGetMemoRequest();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 8) {
            break;
          }

          message.id = reader.int32();
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },

  create(base?: DeepPartial<GetMemoRequest>): GetMemoRequest {
    return GetMemoRequest.fromPartial(base ?? {});
  },

  fromPartial(object: DeepPartial<GetMemoRequest>): GetMemoRequest {
    const message = createBaseGetMemoRequest();
    message.id = object.id ?? 0;
    return message;
  },
};

function createBaseGetMemoResponse(): GetMemoResponse {
  return { memo: undefined };
}

export const GetMemoResponse = {
  encode(message: GetMemoResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
    if (message.memo !== undefined) {
      Memo.encode(message.memo, writer.uint32(10).fork()).ldelim();
    }
    return writer;
  },

  decode(input: _m0.Reader | Uint8Array, length?: number): GetMemoResponse {
    const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseGetMemoResponse();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 10) {
            break;
          }

          message.memo = Memo.decode(reader, reader.uint32());
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },

  create(base?: DeepPartial<GetMemoResponse>): GetMemoResponse {
    return GetMemoResponse.fromPartial(base ?? {});
  },

  fromPartial(object: DeepPartial<GetMemoResponse>): GetMemoResponse {
    const message = createBaseGetMemoResponse();
    message.memo = (object.memo !== undefined && object.memo !== null) ? Memo.fromPartial(object.memo) : undefined;
    return message;
  },
};

function createBaseCreateMemoRequest(): CreateMemoRequest {
  return { memo: undefined };
}

export const CreateMemoRequest = {
  encode(message: CreateMemoRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
    if (message.memo !== undefined) {
      Memo.encode(message.memo, writer.uint32(10).fork()).ldelim();
    }
    return writer;
  },

  decode(input: _m0.Reader | Uint8Array, length?: number): CreateMemoRequest {
    const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseCreateMemoRequest();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 10) {
            break;
          }

          message.memo = Memo.decode(reader, reader.uint32());
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },

  create(base?: DeepPartial<CreateMemoRequest>): CreateMemoRequest {
    return CreateMemoRequest.fromPartial(base ?? {});
  },

  fromPartial(object: DeepPartial<CreateMemoRequest>): CreateMemoRequest {
    const message = createBaseCreateMemoRequest();
    message.memo = (object.memo !== undefined && object.memo !== null) ? Memo.fromPartial(object.memo) : undefined;
    return message;
  },
};

function createBaseCreateMemoResponse(): CreateMemoResponse {
  return { memo: undefined };
}

export const CreateMemoResponse = {
  encode(message: CreateMemoResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
    if (message.memo !== undefined) {
      Memo.encode(message.memo, writer.uint32(10).fork()).ldelim();
    }
    return writer;
  },

  decode(input: _m0.Reader | Uint8Array, length?: number): CreateMemoResponse {
    const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseCreateMemoResponse();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 10) {
            break;
          }

          message.memo = Memo.decode(reader, reader.uint32());
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },

  create(base?: DeepPartial<CreateMemoResponse>): CreateMemoResponse {
    return CreateMemoResponse.fromPartial(base ?? {});
  },

  fromPartial(object: DeepPartial<CreateMemoResponse>): CreateMemoResponse {
    const message = createBaseCreateMemoResponse();
    message.memo = (object.memo !== undefined && object.memo !== null) ? Memo.fromPartial(object.memo) : undefined;
    return message;
  },
};

function createBaseUpdateMemoRequest(): UpdateMemoRequest {
  return { memo: undefined, updateMask: undefined };
}

export const UpdateMemoRequest = {
  encode(message: UpdateMemoRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
    if (message.memo !== undefined) {
      Memo.encode(message.memo, writer.uint32(10).fork()).ldelim();
    }
    if (message.updateMask !== undefined) {
      FieldMask.encode(FieldMask.wrap(message.updateMask), writer.uint32(18).fork()).ldelim();
    }
    return writer;
  },

  decode(input: _m0.Reader | Uint8Array, length?: number): UpdateMemoRequest {
    const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseUpdateMemoRequest();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 10) {
            break;
          }

          message.memo = Memo.decode(reader, reader.uint32());
          continue;
        case 2:
          if (tag !== 18) {
            break;
          }

          message.updateMask = FieldMask.unwrap(FieldMask.decode(reader, reader.uint32()));
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },

  create(base?: DeepPartial<UpdateMemoRequest>): UpdateMemoRequest {
    return UpdateMemoRequest.fromPartial(base ?? {});
  },

  fromPartial(object: DeepPartial<UpdateMemoRequest>): UpdateMemoRequest {
    const message = createBaseUpdateMemoRequest();
    message.memo = (object.memo !== undefined && object.memo !== null) ? Memo.fromPartial(object.memo) : undefined;
    message.updateMask = object.updateMask ?? undefined;
    return message;
  },
};

function createBaseUpdateMemoResponse(): UpdateMemoResponse {
  return { memo: undefined };
}

export const UpdateMemoResponse = {
  encode(message: UpdateMemoResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
    if (message.memo !== undefined) {
      Memo.encode(message.memo, writer.uint32(10).fork()).ldelim();
    }
    return writer;
  },

  decode(input: _m0.Reader | Uint8Array, length?: number): UpdateMemoResponse {
    const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseUpdateMemoResponse();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 10) {
            break;
          }

          message.memo = Memo.decode(reader, reader.uint32());
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },

  create(base?: DeepPartial<UpdateMemoResponse>): UpdateMemoResponse {
    return UpdateMemoResponse.fromPartial(base ?? {});
  },

  fromPartial(object: DeepPartial<UpdateMemoResponse>): UpdateMemoResponse {
    const message = createBaseUpdateMemoResponse();
    message.memo = (object.memo !== undefined && object.memo !== null) ? Memo.fromPartial(object.memo) : undefined;
    return message;
  },
};

function createBaseDeleteMemoRequest(): DeleteMemoRequest {
  return { id: 0 };
}

export const DeleteMemoRequest = {
  encode(message: DeleteMemoRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
    if (message.id !== 0) {
      writer.uint32(8).int32(message.id);
    }
    return writer;
  },

  decode(input: _m0.Reader | Uint8Array, length?: number): DeleteMemoRequest {
    const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseDeleteMemoRequest();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 8) {
            break;
          }

          message.id = reader.int32();
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },

  create(base?: DeepPartial<DeleteMemoRequest>): DeleteMemoRequest {
    return DeleteMemoRequest.fromPartial(base ?? {});
  },

  fromPartial(object: DeepPartial<DeleteMemoRequest>): DeleteMemoRequest {
    const message = createBaseDeleteMemoRequest();
    message.id = object.id ?? 0;
    return message;
  },
};

function createBaseDeleteMemoResponse(): DeleteMemoResponse {
  return {};
}

export const DeleteMemoResponse = {
  encode(_: DeleteMemoResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
    return writer;
  },

  decode(input: _m0.Reader | Uint8Array, length?: number): DeleteMemoResponse {
    const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseDeleteMemoResponse();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },

  create(base?: DeepPartial<DeleteMemoResponse>): DeleteMemoResponse {
    return DeleteMemoResponse.fromPartial(base ?? {});
  },

  fromPartial(_: DeepPartial<DeleteMemoResponse>): DeleteMemoResponse {
    const message = createBaseDeleteMemoResponse();
    return message;
  },
};

export type MemoServiceDefinition = typeof MemoServiceDefinition;
export const MemoServiceDefinition = {
  name: "MemoService",
  fullName: "slash.api.v1.MemoService",
  methods: {
    /** ListMemos returns a list of memos. */
    listMemos: {
      name: "ListMemos",
      requestType: ListMemosRequest,
      requestStream: false,
      responseType: ListMemosResponse,
      responseStream: false,
      options: {
        _unknownFields: {
          578365826: [new Uint8Array([15, 18, 13, 47, 97, 112, 105, 47, 118, 49, 47, 109, 101, 109, 111, 115])],
        },
      },
    },
    /** GetMemo returns a memo by id. */
    getMemo: {
      name: "GetMemo",
      requestType: GetMemoRequest,
      requestStream: false,
      responseType: GetMemoResponse,
      responseStream: false,
      options: {
        _unknownFields: {
          8410: [new Uint8Array([2, 105, 100])],
          578365826: [
            new Uint8Array([
              20,
              18,
              18,
              47,
              97,
              112,
              105,
              47,
              118,
              49,
              47,
              109,
              101,
              109,
              111,
              115,
              47,
              123,
              105,
              100,
              125,
            ]),
          ],
        },
      },
    },
    /** CreateMemo creates a memo. */
    createMemo: {
      name: "CreateMemo",
      requestType: CreateMemoRequest,
      requestStream: false,
      responseType: CreateMemoResponse,
      responseStream: false,
      options: {
        _unknownFields: {
          578365826: [
            new Uint8Array([
              21,
              58,
              4,
              109,
              101,
              109,
              111,
              34,
              13,
              47,
              97,
              112,
              105,
              47,
              118,
              49,
              47,
              109,
              101,
              109,
              111,
              115,
            ]),
          ],
        },
      },
    },
    /** UpdateMemo updates a memo. */
    updateMemo: {
      name: "UpdateMemo",
      requestType: UpdateMemoRequest,
      requestStream: false,
      responseType: UpdateMemoResponse,
      responseStream: false,
      options: {
        _unknownFields: {
          8410: [new Uint8Array([16, 109, 101, 109, 111, 44, 117, 112, 100, 97, 116, 101, 95, 109, 97, 115, 107])],
          578365826: [
            new Uint8Array([
              31,
              58,
              4,
              109,
              101,
              109,
              111,
              26,
              23,
              47,
              97,
              112,
              105,
              47,
              118,
              49,
              47,
              109,
              101,
              109,
              111,
              115,
              47,
              123,
              109,
              101,
              109,
              111,
              46,
              105,
              100,
              125,
            ]),
          ],
        },
      },
    },
    /** DeleteMemo deletes a memo by id. */
    deleteMemo: {
      name: "DeleteMemo",
      requestType: DeleteMemoRequest,
      requestStream: false,
      responseType: DeleteMemoResponse,
      responseStream: false,
      options: {
        _unknownFields: {
          8410: [new Uint8Array([2, 105, 100])],
          578365826: [
            new Uint8Array([
              20,
              42,
              18,
              47,
              97,
              112,
              105,
              47,
              118,
              49,
              47,
              109,
              101,
              109,
              111,
              115,
              47,
              123,
              105,
              100,
              125,
            ]),
          ],
        },
      },
    },
  },
} as const;

type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;

export type DeepPartial<T> = T extends Builtin ? T
  : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
  : T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
  : Partial<T>;

function toTimestamp(date: Date): Timestamp {
  const seconds = date.getTime() / 1_000;
  const nanos = (date.getTime() % 1_000) * 1_000_000;
  return { seconds, nanos };
}

function fromTimestamp(t: Timestamp): Date {
  let millis = (t.seconds || 0) * 1_000;
  millis += (t.nanos || 0) / 1_000_000;
  return new Date(millis);
}
